<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<title>商品管理</title>
		<link href="plugin/date/date.css" rel="stylesheet">
		<link href="bootstrap/css/bootstrap3.min.css" rel="stylesheet">
		<link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
		<script src="js/jquery.min.js"></script>
		<link rel="stylesheet" href="css/nav.css" />
		<style>
			.form-group-update {
				margin-right: 2%;
			}
			#bannerImg,#classificationImg{display: none;}
		</style>
	</head>

	<body>
		<!--导航-->
	    <nav class="navbar navbar-inverse">
	      <div class="container-fluid">
	        <div class="navbar-header">
	          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
	            <span class="sr-only">Toggle navigation</span>
	            <span class="icon-bar"></span>
	            <span class="icon-bar"></span>
	            <span class="icon-bar"></span>
	          </button>
		          	<a class="navbar-brand" href=""><img src="images/admin_logo.png" alt=""></a>
	        </div>

	        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
	          <ul class="nav navbar-nav" id="nav">

	          </ul>
	          <ul class="nav navbar-nav navbar-right">
	            <li class="dropdown">
	              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">欢迎您：<span id="uname"></span><span class="caret"></span></a>
	              <ul class="dropdown-menu" role="menu">
	                <li><a href="change_pass.html">修改密码</a></li>
	                <li><a id="loginOut" href="#">退出登陆</a></li>
	              </ul>
	            </li>
	          </ul>
	        </div>
	      </div>
	    </nav>
		<div class="container-fluid">
			<div class="row bcert-box">
				<ol class="breadcrumb">
				  <li><a href="javascript:;">主页</a></li>
				  <li>商品管理</li>
				  <li class="active">商品管理</li>
				</ol>
				<form class="form-inline searchForm" id="excleBtn">
		          <div class="form-group">
		            <span class="theme-title">商品分类:</span>
		            <select class="form-control drop-down" name='gcId1' id="gcId1">
		              <option value="">全部</option>
		              <option value="1">分类1</option>
		              <option value="2">分类2</option>
		            </select>
		          </div>
				  <div class="form-group">
				   <span class="theme-title">上架:</span>
				   <select class="form-control drop-down" name='goodsState' id="goodsState">
					 <option value="">全部</option>
					 <option value="1">在售中</option>
					 <option value="0">下架</option>
					 <option value="10">违规下架</option>
				   </select>
				 </div>
				 <div class="form-group">
				  <span class="theme-title">审核状态:</span>
				  <select class="form-control drop-down" name='goodsVerify' id="goodsVerify">
					<option value="">全部</option>
					<option value="1">通过</option>
					<option value="0">未通过</option>
					<option value="10">审核中</option>
				  </select>
				</div>
		          <div class="form-group">
		              <input type="text" class="form-control" style="padding-left:12px;" name="userId" id="goodsId" placeholder="商品id">
		          </div>
		          <div class="form-group">
		              <input type="text" class="form-control" style="padding-left:12px;" name="orderNo" id="goodsName" placeholder="商品名称">
		          </div>
		          <div class="form-group">
		              <input type="text" class="form-control" style="padding-left:12px;" name="cbkMobile" id="storeName" placeholder="店铺名称">
		          </div>
		          <div class="form-group">
		            <!-- <button type="button" class="btn btn-primary btn-success" id="Reset"></span>重置</button> -->
		            <button type="button" class="btn btn-primary btn-default" id="QueryBtn" data-toggle="button" aria-pressed="false" autocomplete="off">查询</button>
		            <!-- <button type="button" class="btn btn-primary btn-success" id="dlexcle"></span>&nbsp;导出excle</button> -->
		          </div>
		        </form>
				<div class="table">
		          <table class="table table-bordered table-striped" id="dataList">

		          </table>
		        </div>
		      </div>
		      <!-- 分页 -->
		        <nav aria-label="...">
		          <div class="">
		            <span id="pageNum">共&nbsp;<strong></strong>&nbsp;页&nbsp;/&nbsp;</span><span id="totalNum">&nbsp;<strong>0</strong>&nbsp;条数据</span>
		          </div>
		          <ul id="example"></ul>
		        </nav>
			</div>
		</div>
		<div class="modal fade" tabindex="-1" role="dialog" id="gridSystemModal" aria-labelledby="gridSystemModalLabel">
	    <div class="modal-dialog" role="document">
	        <div class="modal-content ztreeIpt">
	            <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
	                </button>
	                 <h4 class="modal-title" id="gridSystemModalLabel">查看</h4>
	            </div>
	            <div class="modal-body">
					<div class="form-group">
						<label class="col-sm-2 control-label goods-lb-l">分类名</label>
						<div class="col-sm-10 goods-lb-r">
							<input type="text" class="form-control" id="name" placeholder="分类名">
						</div>
					</div>
					<div class="form-group" id="bannerImg">
						<label class="col-sm-2 control-label goods-lb-l">广告图片</label>
						<div class="col-sm-10 goods-lb-r">
							<form id="addB" enctype="multipart/form-data">
								<input type="file" multiple="" onchange="imgup(this,$('#addB'))" class="form-control"  name="file" placeholder="广告图片">
								<input type="hidden" name="" id="gcAdImage" value="">
								<p>图片尺寸：300*200</p>
								<div class="addB">
									<img class="" id="gcAdImageBox" style="width:140px;" src="" alt="">
								</div>

							</form>
						</div>
					</div>
					<div class="form-group"  id="classificationImg">
						<label class="col-sm-2 control-label goods-lb-l">分类图片</label>
						<div class="col-sm-10 goods-lb-r">
							<form id="addF" enctype="multipart/form-data">
								<input type="file" multiple="" onchange="imgup(this,$('#addF'))" class="form-control" name="file" placeholder="分类图片">
								<input type="hidden" name="" id="gcImage" value="">
								<p>图片尺寸：300*200</p>
								<div class="addF">
									<img class="" id="gcImageBox" style="width:140px;" src="" alt="">
								</div>
							</form>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label goods-lb-l">排序</label>
						<div class="col-sm-10 goods-lb-r">
							<input type="text" class="form-control" id="gcSort" placeholder="排序">
						</div>
					</div>
	            </div>
				<!--待审核-->
	            <div class="modal-footer pendingApproval">
	                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	                <button type="button" class="btn btn-primary" id="ztreeBtn">提交</button>
	            </div>
	        </div>
		        <!-- /.modal-content -->
	    </div>
	    <!-- /.modal-dialog -->
	</div>
	</body>
</html>
<script type="text/javascript" src="plugin/layer/layer.js"></script>
<script type="text/javascript" src="js/cookie.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript" src="js/bootstrap-paginator.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script>
	var pageUrls = serverURL + '/platform/getGoodsList';
	function tableList(){
		data = {
			'goodsId':$('#goodsId').val(),
			'goodsName':$('#goodsName').val(),
			'gcId1':$('#gcId1').val(),
			'storeName':$('#storeName').val(),
			'goodsState':$('#goodsState').val(),
			'goodsVerify':$('#goodsVerify').val(),
			'page': page,
			'pageSize': pagesize
		}
		data.page = 1
		ajax(
			pageUrls,
			data,
			pageNumList,
			'post',
			'json'
		)
	}
	$('#QueryBtn').click(function(){
		tableList()
	})
	$(document).ready(function() {
		tableList()
	});
	//数据渲染
	function OpendList(res){
	    var result = '';
		console.log(res)
	    $('#dataList').empty();
	    $('#dataList').append(
	      '<tr>' +
	      '<th>商品id</th>' +
	      '<th>商品名称</th>' +
	      '<th>商品分类</th>' +
	      '<th>店铺名称</th>' +
	      '<th>商品价格</th>' +
		  '<th>物券</th>' +
		  '<th>库存</th>' +
		  '<th>商品状态</th>' +
		  '<th>审核状态</th>' +
		  '<th>操作</th>' +
	      '</tr>'
	    );
	    for (var i = 0; i < res.data.list.length; i++) {
	        var time = getMyDate(res.data.list[i].createTime);
	        result +=
	               '<tr>'+
	                 '<td>'+ res.data.list[i].goodsId +'</td>'+
	                 '<td>'+ res.data.list[i].goodsName +'</td>'+
	                 '<td>'+ res.data.list[i].gcId1  + '>' +res.data.list[i].gcId2 + '>'+res.data.list[i].gcId3 +'</td>'+
	                 '<td>'+ res.data.list[i].storeName +'</td>'+
	                 '<td>'+ res.data.list[i].goodsPrice +'</td>'+
	                 '<td>'+ res.data.list[i].couponPrice +'</td>'+
					 '<td>'+ res.data.list[i].goodsStorage +'</td>'
					 if (res.data.list[i].goodState == 1) {
						result +='<td>出售中</td>'
					}else if (res.data.list[i].goodState == 0) {
						result +='<td>下架</td>'
					}else if (res.data.list[i].goodState == 10) {
						result +='<td>违规下架</td>'
					}else if (res.data.list[i].goodState == 20) {
						result +='<td>已删除</td>'
					}else{
 					   result += ''
 				   }
					if (res.data.list[i].goodsVerify == 1) {
					   result +='<td>通过</td>'
				   }else if (res.data.list[i].goodsVerify == 0) {
					   result +='<td>未通过</td>'
				   }else if (res.data.list[i].goodsVerify == 10) {
					   result +='<td>审核中</td>'
				   }else{
					   result += ''
				   }
				   result += '<td class="text-center"><button class="btn btn-primary btn-sm recommend" data-toggle="modal" data-target=".bs-example-modal-sm" onclick="window.open(\'goods_particulars.html?id='+res.data.list[i].goodsId+'\') ">查看</button>&nbsp;&nbsp;'
				   if (res.data.list[i].goodState == 1 && res.data.list[i].goodsVerify == 1) {
						result +='<button data-id="'+ res.data.list[i].goodsId +'" onclick="underGoods('+ res.data.list[i].goodsId +',10)" type="button" class="btn btn-primary btn-sm  btn-success" data-toggle="modal" data-target=".bs-example-modal-sm" id="add-city">违规下架</button>'
				   }
				   if (res.data.list[i].goodsVerify == 10) {
						result +='<button data-id="'+ res.data.list[i].goodsId +'" onclick="auditApproval('+ res.data.list[i].goodsId +',1)"  type="button" class="btn btn-primary btn-sm  btn-success" data-toggle="modal" data-target=".bs-example-modal-sm" id="add-city">审核通过</button> &nbsp;&nbsp;'+
						'<button data-id="'+ res.data.list[i].goodsId +'"  onclick="nonApproval('+ res.data.list[i].goodsId +',0)" type="button" class="btn btn-danger btn-sm  btn-success" data-toggle="modal" data-target=".bs-example-modal-sm" id="add-city">审核不通过</button>'
				   }
	                //  '<td>'+ time +'</td>'+
	               result +='</td></tr>'
	    }
	    $('#dataList').append(result)
	  }

	  //商品下架
	  function underGoods(id,goodsState){
		  layer.prompt({title: '填写违规下架理由', formType: 2}, function(text, index){
			  layer.close(index);
			  var data= {
				  'goodsId':id,
				  'goodsState':goodsState,
				  'goodsStateremark':text
			  }
			  var cbk = function (res){
				layer.msg(res.msg)
				tableList()
			  }
			  ajax(
				  serverURL+'/platform/soltOutGoods',
				  data,
				  cbk,
				  'post',
				  'json'
			  )
		  });
	  }


	//通过审核
	function auditApproval(id,goodsVerify){
		layer.confirm('确定要审核通过？', {
  		  btn: ['确定','取消'] //按钮
  		}, function(){
			var data= {
				'goodsId':id,
				'goodsVerify':goodsVerify,
				// 'goodsVerifyremark':text
			}
			var cbk = function (res){
				layer.msg(res.msg)
				tableList()
			}
			ajax(
				serverURL+'/platform/checkGoods',
				data,
				cbk,
				'post',
				'json'
			)
  		}, function(){

  		});
	}
	function nonApproval(id,goodsVerify){
		layer.prompt({title: '请填写审核不通过原因', formType: 2}, function(text, index){
		    layer.close(index);
			var data= {
				'goodsId':id,
				'goodsVerify':goodsVerify,
				'goodsVerifyremark':text,
			}
			var cbk = function (res){
				layer.msg(res.msg)
				tableList()
			}
			ajax(
				serverURL+'/platform/checkGoods',
				data,
				cbk,
				'post',
				'json'
			)
		});
	}
	//数据清空
	$('#gridSystemModal').on('hidden.bs.modal', function (e) {

	})

</script>
